package com.thinkgem.jeesite.modules.tgb.SpringActivemq.mq.consumer.topic;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.service.OfficeService;
import com.thinkgem.jeesite.modules.sys.web.OfficeController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author liang
 * @description Topic消息监听器,监听新增的部门
 */
@Component("topicDeptReceiver")
public class TopicDeptReceiver implements MessageListener {

    @Autowired
    private OfficeService officeService;

    @Override
    public void onMessage(Message message) {
            try {
                String port = new Global().getConfig("clientId");//获取某一个key的value: clientId=jims-oa
                if (StringUtils.isNotBlank(message.getStringProperty("type")) && message.getStringProperty("type").equals(port)) {
                } else {
                    System.out.println("TopicReceiver1接收到消息:" + ((TextMessage) message).getText());
                    String type = message.getStringProperty("type");//update,add,delete
                    officeService.saveDept(type,((TextMessage) message).getText());
                }
            } catch (JMSException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

    }

}
